﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ICAM.View
{
    /// <summary>
    /// ExitView.xaml 的交互逻辑
    /// </summary>
    public partial class ExitView : DialogWindow
    {
        public ExitView()
        {
            InitializeComponent();
            this.Loaded += ExitView_Loaded;
        }

        private void ExitView_Loaded(object sender, RoutedEventArgs e)
        {
            var mainViewModule = this.DataContext as MainViewModule;
            if (mainViewModule == null)
                return;

            var collection = mainViewModule.AlaramCollection;

            int level_1 = 0;
            int level_2 = 0;

            foreach (var alaramInfo in collection)
            {
                if (alaramInfo.AlarmDealType != "未处理")
                {
                    continue;
                }
                if (alaramInfo.AlarmLevel == "1")
                {
                    level_1 += 1;
                }
                else if (alaramInfo.AlarmLevel == "2")
                {
                    level_2 += 1;
                }
            }
            StringBuilder builder = new StringBuilder();
            string level_1_msg = string.Empty;
            string level_2_msg = string.Empty;
            //今日还有2个1级事件，3个2级事件未处理
            if (level_1 > 0)
            {
                level_1_msg = $"{level_1}个1级事件";
            }
            if (level_2 > 0)
            {
                level_2_msg = $"{level_2}个2级事件";
            }

            if (!string.IsNullOrEmpty(level_1_msg))
            {
                builder.Append(level_1_msg);
            }
            if (!string.IsNullOrEmpty(builder.ToString()) && !string.IsNullOrEmpty(level_2_msg))
            {
                builder.Append("，");
            }
            if (!string.IsNullOrEmpty(level_2_msg))
            {
                builder.Append(level_2_msg);
            }

            if (!string.IsNullOrEmpty(builder.ToString()))
            {
                infoTxt.Text = $"今日还有{builder.ToString()}未处理";
            }
            else
            {
                infoTxt.Text = "";
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }
    }
}
